//
//  AddSosListTableViewCell.m
//  Leo01
//
//  Created by 张旭 on 15/9/27.
//  Copyright (c) 2015年 张旭. All rights reserved.
//

#import "AddSosListTableViewCell.h"
#import "DataManager.h"

@implementation AddSosListTableViewCell
@synthesize navController;
@synthesize avatarImage;
@synthesize nameLabel;
@synthesize chooseOrNot;
@synthesize phoneLabel;

-(AddSosListTableViewCell *)getandSetDataByManager:(Manager *)manager{
    nameLabel.text = manager.alias;
    //DataManager *dataManager=[[DataManager alloc]init];
    //Contact *contact=[dataManager getContact:[subdic valueForKey:@"contact_id"]];
    phoneLabel.text=manager.phone;
    
    NSRange range;
    NSString *photoNameString;
    range = [manager.pic_url rangeOfString:@"/headimg/"];
    if (range.location != NSNotFound) {
        NSLog(@"found at location = %d, length = %d",range.location,range.length);
        photoNameString=[manager.pic_url substringFromIndex:range.location];
        NSLog(@"%@",photoNameString);
        
    }else{
        NSLog(@"Not Found");
    }
    //头像切圆代码
    self.avatarImage.layer.cornerRadius = avatarImage.bounds.size.width / 2;
    self.avatarImage.clipsToBounds = YES;

    
    if(manager.pic_url!=NULL&&![manager.pic_url isEqualToString:@"(null)"]&&![manager.pic_url isEqualToString:@""])
    {
        NSString *headUrl=[NSString stringWithFormat:@"%@%@",[Tooler getDocumentDirectory],photoNameString];
        avatarImage.image=[UIImage imageWithContentsOfFile:headUrl];
    }
    else
    {
        avatarImage.image = [UIImage imageNamed:@"avater_brother"];
    }
    
    
    
    return self;
}

-(AddSosListTableViewCell *)getandSetDataByContact:(Contact *)contact{
    nameLabel.text =contact.contactname;
    //DataManager *dataManager=[[DataManager alloc]init];
    //Contact *contact=[dataManager getContact:[subdic valueForKey:@"contact_id"]];
    phoneLabel.text=contact.phoneNum;
    
    NSRange range;
    NSString *photoNameString;
    range = [contact.photo_url rangeOfString:@"/headimg/"];
    if (range.location != NSNotFound) {
        NSLog(@"found at location = %d, length = %d",range.location,range.length);
        photoNameString=[contact.photo_url substringFromIndex:range.location];
        NSLog(@"%@",photoNameString);
        
    }else{
        NSLog(@"Not Found");
    }
    //头像切圆代码
    self.avatarImage.layer.cornerRadius = avatarImage.bounds.size.width / 2;
    self.avatarImage.clipsToBounds = YES;

    
    if(contact.photo_url!=NULL&&![contact.photo_url isEqualToString:@"(null)"]&&![contact.photo_url isEqualToString:@""])
    {
        NSString *headUrl=[NSString stringWithFormat:@"%@%@",[Tooler getDocumentDirectory],photoNameString];
        avatarImage.image=[UIImage imageWithContentsOfFile:headUrl];
    }
    else
    {
        avatarImage.image = [UIImage imageNamed:@"avater_brother"];
    }
    
    
    
    return self;
}






-(AddSosListTableViewCell *)getandSetData:(NSDictionary *)subdic{
    nameLabel.text = [subdic objectForKey:@"name"];
    DataManager *dataManager=[[DataManager alloc]init];
    Contact *contact=[dataManager getContact:[subdic valueForKey:@"contact_id"]];

    
    NSRange range;
    NSString *photoNameString;
    range = [contact.photo_url rangeOfString:@"/headimg/"];
    if (range.location != NSNotFound) {
        NSLog(@"found at location = %d, length = %d",range.location,range.length);
        photoNameString=[contact.photo_url substringFromIndex:range.location];
        NSLog(@"%@",photoNameString);
        
    }else{
        NSLog(@"Not Found");
    }
    //头像切圆代码
    self.avatarImage.layer.cornerRadius = avatarImage.bounds.size.width / 2;
    self.avatarImage.clipsToBounds = YES;
    
    if(contact.photo_url!=NULL&&![contact.photo_url isEqualToString:@"(null)"]&&![contact.photo_url isEqualToString:@""])
    {
        NSString *headUrl=[NSString stringWithFormat:@"%@%@",[Tooler getDocumentDirectory],photoNameString];
        avatarImage.image=[UIImage imageWithContentsOfFile:headUrl];
    }
    else
    {
        avatarImage.image = [UIImage imageNamed:@"avater_brother"];
    }

    
    
    return self;
}

- (void)awakeFromNib {
    // Initialization code
    nameLabel.font=[UIFont boldSystemFontOfSize:17];
}

-(void)setChooseStatus:(Boolean)choose{
    if (choose) {
        chooseOrNot.text = @"✔︎";
    }
    else
        chooseOrNot.text = @"";
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];
//    if (selected) {
//        chooseOrNot.text = @"✔︎";
//    }
//    else {
//        chooseOrNot.text = @"";
//    }
    // Configure the view for the selected state
}

@end
